-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance crypto/sig.js coverage #17426
Conversation
{ | ||
const Verify = crypto.Verify; | ||
const instance = Verify('SHA256'); | ||
assert.ok(instance instanceof Verify, 'call sign constructor without new'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sign -> verify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I made a mistake.
Thank you for your review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but the assert message should be adjusted, IMHO.
{ | ||
const Sign = crypto.Sign; | ||
const instance = Sign('SHA256'); | ||
assert.ok(instance instanceof Sign, 'call sign constructor without new'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message here seems to be more of a description of the test than communicate what was expected. Maybe something like "expected Sign to return a new instance when called without new
keyword"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for review.
I got it. I'll revise error message.
{ | ||
const Verify = crypto.Verify; | ||
const instance = Verify('SHA256'); | ||
assert.ok(instance instanceof Verify, 'call verify constructor without new'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
const Sign = crypto.Sign; | ||
const instance = Sign('SHA256'); | ||
assert.ok(instance instanceof Sign, 'Sign is expected to return a new \ | ||
instance when called without `new` keyword'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, two more things:
assert
instead ofassert.ok
- We usually try to break strings using + and line them up beneath each other, so something like this:
assert(instance instanceof Sign, 'Sign is expected to return a new instance ' +
'when called without `new` keyword');
Same below. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind.
assert instead of assert.ok
What difference between assert.ok
and assert
?
I think assert()
is better because there are fewer characters, right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert.ok
is just an alias for assert
(or, well, the other way around...). Not better but I think in general we try to use assert
.
The practical difference in this case is it lets us fit that first line instead of having to split everything significantly more awkwardly. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your detailed information.
I understood that assert
was better.
Landed in 0ab98f1 |
- Call Sign without new - Call Verify without new - Call Verify#verify with options.padding !== options.padding >> 0 - Call Verify#verify with options.saltLength !== options.saltLength >> 0 PR-URL: #17426 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
- Call Sign without new - Call Verify without new - Call Verify#verify with options.padding !== options.padding >> 0 - Call Verify#verify with options.saltLength !== options.saltLength >> 0 PR-URL: #17426 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
- Call Sign without new - Call Verify without new - Call Verify#verify with options.padding !== options.padding >> 0 - Call Verify#verify with options.saltLength !== options.saltLength >> 0 PR-URL: #17426 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
I added these case:
Sign
without newVerify
without newVerify#verify
withoptions.padding !== options.padding >> 0
Verify#verify
withoptions.saltLength !== options.saltLength >> 0
Current coverage: https://coverage.nodejs.org/coverage-06e1b0386196f8f8/root/internal/crypto/sig.js.html
After this PR: crypto/sig.js become 100% covered even in branch coverage.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test